package com.kelvin.oocl.crm.util;

import java.io.PrintStream;

import com.kelvin.oocl.crm.entity.Customer;
import com.kelvin.oocl.crm.exception.LinkListIndexOutOfBoundException;

public class FormatPrinter {
	public static String badFormatMsg= "The format of the parameter is bad!";
	
	public static void printOperationResult(boolean flag,PrintStream out){
		if(flag){
			out.println("  Operation success!");
		}else {
			out.print("  Operation fail!");
		}
	}
	
	public static void printCustomers(MyLinkList<Customer> customers,PrintStream out){
		if(customers.getSize()==0 || null==customers){
			out.println("  Can't not find the customer info!");
		}else {
			for (int i = 0; i < customers.getSize(); i++) {
				try {
					out.println("  "+customers.get(i));
				} catch (LinkListIndexOutOfBoundException e) {
					showGettintExceptionMsg(e, out);
				}
			}
		}
	}
	
	public static void printBadParameterMsg(Exception e,PrintStream out){
		out.println("  "+e.getMessage());
		out.println("  You can use the 'H [command]' command to get help info of the command!");
	}
	
	public static void showGettintExceptionMsg(Exception e,PrintStream out){
		out.println("  when getting element from MyLinkList, it encounter a exception!");
		out.print("  "+e.getMessage());
	}  
	
	public static void showCommondNotFound(String s,PrintStream out){
		out.println("  "+s+" is not a conmond,pls input the correct commond!");
	}
	
	public static void showHelp(PrintStream out){
		showL(out);
		showA(out);
		showD(out);
		showU(out);
		showO(out);
		showQ(out);
		out.println("  H [command]  ==>to get operation instruction of the commond and you can view all operation");
		out.println("                  instructions of all commond by only 'H'!");
	}

	public static void showQ(PrintStream out) {
		out.println("  Q  ==>to stop the program and quit!");
	}

	public static void showO(PrintStream out) {
		out.println("  O [id or name]  ==>to sort the customers list by id or name!");
	}

	public static void showU(PrintStream out) {
		out.println("  U [id] [name:xx,sex:xx...]  ==>to update the customer info by id!");
	}

	public static void showD(PrintStream out) {
		out.println("  D [id]  ==>to delete a customer by id!");
	}

	public static void showA(PrintStream out) {
		out.println("  A [name:xx,sex:xx...]  ==>to add a customer info!");
	}

	public static void showL(PrintStream out) {
		out.println("  L [name]  ==>to show the costomer info by name and you can show all customers by only 'L'!");
	}

	public static void showTipHelp(PrintStream out) {
		out.println("You can input the follow commond to do opetation!");
		showHelp(out);
	}
}
